import Http from '@/services/api/index';
const appInstance=getApp();
const BASE_URL= appInstance.globalData.baseUrl;
Page({
  data: {baseUrl: BASE_URL,
    enlargeIndexes: [],
    dynamicClass: 'animation',
    progress: "35%",
    currentIndex: 1,
    levelList: [1, 2, 3, 4, 5, 6]
  },
  onLoad() {
    this.updateEnlargeIndexes(2); // 初始化
  },
  onShow() {
    this.setData({
      dynamicClass: 'animation'
    })
  },
  onHide() {
    this.setData({
      dynamicClass: ''
    })
  },
  tapSwiperChange(e) {
    console.log(e)
    const {
      index
    } = e.currentTarget.dataset;
    console.log(index)

    let {
      levelList
    } = this.data;
    this.setData({
      currentIndex: index
    })
    if (index + 1 == levelList.length) {
      this.updateEnlargeIndexes(0);
      return;
    }
    this.updateEnlargeIndexes(index + 1);
  },
  swiperChange(event) {
    let {
      current
    } = event.detail;
    console.log(current)
    let {
      levelList
    } = this.data;
    this.setData({
      currentIndex: current
    })
    if (current + 1 == levelList.length) {
      this.updateEnlargeIndexes(0);
      return;
    }
    this.updateEnlargeIndexes(current + 1);
  },

  updateEnlargeIndexes: function (current) {
    const {
      levelList
    } = this.data;
    const length = levelList.length;
    const newEnlargeIndexes = [];

    // 计算需要放大的索引（当前项及左右两项）
    newEnlargeIndexes[current] = true;
    this.setData({
      enlargeIndexes: newEnlargeIndexes
    });
  },
  swiperTransitionChange(e) {
    console.log(e)
  }
})